﻿using System.ComponentModel;
using Inspire.Entities;
using Inspire.Main.Exceptions;

namespace Inspire.DataStructures
{
    public class PatronContactMethod : INotifyPropertyChanged
    {

        /// <summary>
        /// MethodName: The name of the method of contact being stored.
        /// </summary>
        private CustomFieldType _methodFieldType = null;
        public CustomFieldType MethodFieldType
        {
            get
            {
                return this._methodFieldType;
            }
            set
            {
                // Ensure the new value is acceptable
                if (value == null)
                {
                    throw new InvalidValueAssignmentException("Attempted to assign invalid value [null] to property [MethodFieldType].");
                }
                else
                {
                    this._methodFieldType = value;
                    this.NotifyPropertyChanged("MethodFieldType");
                }
            }
        }

        /// <summary>
        /// MethodValue: The contact information for this particular method.
        /// </summary>
        private string _methodValue = "";
        public string MethodValue
        {
            get
            {
                return this._methodValue;
            }
            set
            {
                if (value == null)
                {
                    throw new InvalidValueAssignmentException("Attempted to assign invalid value [null] to property [MethodValue].");
                }
                else
                {
                    this._methodValue = value;
                    this.NotifyPropertyChanged("MethodValue");
                }
            }
        }

        /// <summary>
        /// When editing an existing Patron, this may contain custom fields already existing in the database for that Patron.
        /// In these cases, the field may be updated or deleted, but not re-created.
        /// </summary>
        private CustomField _existingField;
        public CustomField ExistingField
        {
            get
            {
                return this._existingField;
            }
            set
            {
                if (value == null)
                {
                    throw new InvalidValueAssignmentException("Attempting to assign invalid value [null] to property [ExistingField].");
                }
                else
                {
                    this._existingField = value;
                    this.NotifyPropertyChanged("ExistingField");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
